home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Doggie-Style Windows w_ Sound! / Source n' Stuff / Source / cleaned.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  3.9 KB  |  183 lines

  1. #include <Fonts.h>
  2. #include <MacWindows.h>
  3. #include <QuickDraw.h>
  4.  
  5. #define kSwell    15
  6. #define kVOffset    6
  7. #define kHOffset    7
  8.  
  9. #define Rand(min, max) (((Random() & 0x7FFF) % ((max)-(min))) + (min))
  10.  
  11. void Swell(Rect * foo);
  12. void Initalize(void);
  13. pascal OSStatus GetWindowBounds(WindowRef window, WindowRegionCode regionCode, Rect *globalBounds);
  14. Boolean DoKey(int k, unsigned char gkm[16]);
  15.  
  16. SndChannelPtr theChannel;
  17.  
  18. Boolean DoKey(int k, unsigned char gkm[16])
  19. {
  20.     return((gkm[k>>3]>>(k&7))&1);
  21. }
  22.  
  23.  
  24. static void Initialize(void)
  25. {
  26.     qd.randSeed = TickCount();
  27.     InitGraf(&qd.thePort);
  28.     InitFonts();
  29.     InitWindows();
  30.     InitMenus();
  31.     InitCursor();
  32.     InitDialogs(nil);
  33.     TEInit();
  34.     MoreMasters();
  35.     SndNewChannel(&theChannel, sampledSynth, initMono, NULL);
  36. }
  37.  
  38. pascal OSStatus GetWindowBounds(WindowRef window, 
  39.             WindowRegionCode       regionCode,Rect *globalBounds)
  40. {
  41.     OSStatus anErr = noErr;
  42. //    GrafPtr savePort;
  43.     Rect    tRect;
  44.  
  45. //    GetPort(&savePort);
  46. //    SetPort(window);
  47.  
  48.     tRect = (*((WindowPeek) window)->contRgn)->rgnBBox;
  49.  
  50.     if (nil != globalBounds)
  51.         *globalBounds = tRect;
  52.     else
  53.         anErr = paramErr;
  54.  
  55. //    SetPort(savePort);
  56.  
  57.     return anErr;
  58. }
  59.  
  60. void Swell(Rect * swellee)
  61. {
  62.     swellee->left -= kSwell;
  63.     if(swellee->left < 0)
  64.         swellee->left = 1;
  65.         
  66.     swellee->right += kSwell;
  67.     swellee->top -= kSwell/2;
  68.     if(swellee->top < 0)
  69.         swellee->top = 1;
  70.         
  71.     swellee->bottom += kSwell*2;
  72. }
  73.  
  74. void main(void)
  75. {
  76.     WindowPeek baseWindow;
  77.     WindowRef tWindowRef1,tWindowRef2,tWindowRef3,tWindowRef4;
  78.     Rect    wRect = { 20,20,200,820}, mainRect;
  79.     Handle wHandle, dHandle;
  80.     unsigned char map[16];
  81.     
  82.     Initialize();
  83.  
  84.     tWindowRef1 = NewCWindow(nil,&wRect,"\pMyWindow1",true,kStandardWindowDefinition,(WindowRef) -1,false,0);
  85.     SetRect(&wRect, 120,75,250,732);
  86.     tWindowRef2 = NewCWindow(nil,&wRect,"\pMyWindow2",true,kStandardWindowDefinition,(WindowRef) -1,false,0);
  87.     SetRect(&wRect, 100,50,220,200);
  88.     tWindowRef3 = NewCWindow(nil,&wRect,"\pMyWindow3",true,kStandardWindowDefinition,(WindowRef) -1,false,0);
  89.     SetRect(&wRect,180,100, 590, 560);
  90.     tWindowRef4 = NewCWindow(nil,&wRect,"\pMyWindow4",true,kStandardWindowDefinition,(WindowRef) -1,false,0);
  91.  
  92.     wHandle = GetResource('snd ', 128);
  93.     dHandle = GetResource('snd ', 129);
  94.  
  95.     GetKeys((unsigned long *)map);
  96.     if(DoKey(56, map))
  97.             return;
  98.  
  99.     baseWindow = (WindowPeek) LMGetWindowList();
  100.     
  101.     if(wHandle)
  102.     {
  103.         HLock(wHandle);
  104. //        SndPlay(theChannel, (SndListHandle)wHandle, false);
  105. //        SndPlay(theChannel, (SndListHandle)wHandle, false);
  106.         HUnlock(wHandle);
  107.     }
  108.  
  109.     (void) GetWindowBounds((WindowPtr) baseWindow,kWindowGlobalPortRgn,&mainRect);
  110.     Swell(&mainRect);
  111.     
  112.     while (nil != baseWindow)
  113.     {
  114.         Point tDelta;
  115.         short direction = Rand(0, 3);
  116.         Rect tRect, * subRect;
  117.         baseWindow = baseWindow->nextWindow;
  118.         if(nil==baseWindow) break;
  119.         
  120.  
  121.         (void) GetWindowBounds((WindowPtr) baseWindow,kWindowGlobalPortRgn,&wRect);
  122.  
  123.         while(SectRect(&mainRect, &wRect, nil))
  124.         {
  125.             tDelta.h = tDelta.v = 0;
  126.             switch(direction)
  127.             {
  128.                 case 0:
  129.                 case 4:
  130.                 case 8:
  131.                 case 12:
  132.                     tDelta.h=kHOffset;
  133.                     break;
  134.                 case 1:
  135.                 case 5:
  136.                 case 9:
  137.                     tDelta.v=-kVOffset;
  138.                     break;
  139.                 case 2:
  140.                 case 6:
  141.                 case 10:
  142.                     tDelta.h=-kHOffset;
  143.                     break;
  144.                 case 3:
  145.                 case 7:
  146.                 case 11:
  147.                     tDelta.v=kVOffset;
  148.                     break;
  149.             }
  150.  
  151.             tDelta.h += Rand(-2,2);
  152.             tDelta.v += Rand(-1,1);
  153.  
  154.             GetKeys((unsigned long *)map);
  155.             if(DoKey(56, map))
  156.                     return;
  157.  
  158.             OffsetRect(&wRect,tDelta.h,tDelta.v);
  159.             MoveWindow((WindowPtr)baseWindow, wRect.left, wRect.top, false);
  160.  
  161. //            (void) GetWindowBounds((WindowPtr) baseWindow,kWindowGlobalPortRgn,&wRect);
  162.             
  163.             SectRect(&qd.screenBits.bounds, &wRect, &tRect);
  164.             if(!EqualRect(&wRect, &tRect))
  165.             {
  166.                 MoveWindow((WindowPtr)baseWindow, wRect.left - tDelta.h, wRect.top - tDelta.v, false);
  167.                 direction++;
  168.                 (void) GetWindowBounds((WindowPtr) baseWindow,kWindowGlobalPortRgn,&wRect);
  169.                 if(dHandle)
  170.                 {
  171.                     HLock(dHandle);
  172. //                    SndPlay(theChannel, (SndListHandle)dHandle, true);
  173.                     HUnlock(dHandle);
  174.                 }
  175.                 
  176.             }
  177.             if(direction > 12)
  178.                 break;
  179.         }
  180.     }
  181. }
  182.  
  183.